import {request} from "@umijs/max";
import {PageParam} from "@/services/common";
import {covertTableData} from "@/utils/tableUtil";

export interface GenerateColumnVO {
        /**
        * id
        */
        id?: string;
        /**
        * 业务id
        */
        businessId?: string;
        /**
        * 列名
        */
        columnName?: string;
        /**
        * 排序
        */
        orderPosition?: number;
        /**
        * 列默认值
        */
        columnDefault?: string;
        /**
        * 是否为可空
        */
        isNullable?: string;
        /**
        * 列数据类型
        */
        dataType?: string;
        /**
        * key
        */
        columnKey?: string;
        /**
        * 列注释
        */
        columnComment?: string;
        /**
        *
        */
        isShow?: boolean;
        /**
        *
        */
        isEdit?: boolean;
        /**
        *
        */
        isQuery?: boolean;
}

export interface GenerateColumnQueryDTO extends PageParam {
        /**
        * id
        */
        id?: string;
        /**
        * 业务id
        */
        businessId?: string;
        /**
        * 列名
        */
        columnName?: string;
        /**
        * 排序
        */
        orderPosition?: number;
        /**
        * 列默认值
        */
        columnDefault?: string;
        /**
        * 是否为可空
        */
        isNullable?: string;
        /**
        * 列数据类型
        */
        dataType?: string;
        /**
        * key
        */
        columnKey?: string;
        /**
        * 列注释
        */
        columnComment?: string;
        /**
        *
        */
        isShow?: boolean;
        /**
        *
        */
        isEdit?: boolean;
        /**
        *
        */
        isQuery?: boolean;
}
export interface GenerateColumnUpdateDTO {
        /**
        * id
        */
        id?: string;
        /**
        * 业务id
        */
        businessId?: string;
        /**
        * 列名
        */
        columnName?: string;
        /**
        * 排序
        */
        orderPosition?: number;
        /**
        * 列默认值
        */
        columnDefault?: string;
        /**
        * 是否为可空
        */
        isNullable?: string;
        /**
        * 列数据类型
        */
        dataType?: string;
        /**
        * key
        */
        columnKey?: string;
        /**
        * 列注释
        */
        columnComment?: string;
        /**
        *
        */
        isShow?: boolean;
        /**
        *
        */
        isEdit?: boolean;
        /**
        *
        */
        isQuery?: boolean;
}

export const getGenerateColumnById = async (id: string) => {
    return request<GenerateColumnVO>(`/api/generateColumn?id=${id}`, {method: 'POST'})
}

export const getGenerateColumnList = async (queryDTO: GenerateColumnQueryDTO) => {
    return request<GenerateColumnVO[]>(`/api/generateColumn/list`, {method: 'POST', data:queryDTO})
}

export const getGenerateColumnPage = async (queryDTO: GenerateColumnQueryDTO) => {
    let response = await request<Array<GenerateColumnVO>>(`/api/generateColumn/page`, {method: 'POST', data:queryDTO})
    return covertTableData(response)
}

export const updateGenerateColumn = async (generateColumnUpdateDTO: GenerateColumnUpdateDTO) => {
    return request<GenerateColumnVO>(`/api/generateColumn/update`, {method: 'POST', data: generateColumnUpdateDTO})
}

export const saveGenerateColumn = async (generateColumnUpdateDTO: GenerateColumnUpdateDTO) => {
    return request<GenerateColumnVO>(`/api/generateColumn/save`, {method: 'POST', data: generateColumnUpdateDTO})
}

export const removeGenerateColumn = async (id: string) => {
    return request<boolean>(`/api/generateColumn/remove?id=${id}`, {method: 'POST'})
}
